package com.online.service_edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.online.service_edu.client.VodClient;
import com.online.service_edu.entity.EduVideo;
import com.online.service_edu.mapper.EduVideoMapper;
import com.online.service_edu.service.EduVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author hdc2008
 * @since 2021-02-11
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {

    @Autowired
    private VodClient vodClient;
    @Autowired
    private EduVideoMapper eduVideoMapper;

    @Override
    public boolean removeSoureVideoIdAndName(String id) {
        System.out.println("id====>"+id);
        boolean flag=eduVideoMapper.removeSourceIdAndName(id);
        if(flag){
            System.out.println("删除成功");
        }
        return flag;
    }

    @Override
    public boolean removeVideo(String id) {
        if(!StringUtils.isEmpty(id)){
            EduVideo eduVideo=baseMapper.selectById(id);
            if(eduVideo!=null){
                if(!StringUtils.isEmpty(eduVideo.getVideoSourceId())){
                    vodClient.deleteVideo(eduVideo.getVideoSourceId());
                }
                baseMapper.deleteById(id);
                return true;
            }
        }
        return false;
    }

    @Override
    public List<EduVideo> getVideoListByChapterId(String id) {
        QueryWrapper<EduVideo> wrapper=new QueryWrapper<>();
        wrapper.eq("chapter_id",id);
        List<EduVideo> eduVideoList = baseMapper.selectList(wrapper);
        return eduVideoList;
    }
}
